package com.kr.aia.powerrp.roleplay;
 
import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.TextView;
import android.widget.Toast;

import com.kr.aia.powerrp.R;
 
public class RPSelectionAdapter extends ArrayAdapter<RPDataVO> {
 
    private Context context;
    private int layoutResourceId;
    private ArrayList<RPDataVO> data;
    
    private int curPosition = -1;
    private int checkedNumber = 0;
 
    public RPSelectionAdapter(Context context, int layoutResourceId, ArrayList<RPDataVO> d) {
    	super(context, layoutResourceId, d);
    	this.context = context;
    	this.layoutResourceId = layoutResourceId;
        this.data=d;
    }
 
    public int getCount() {
        return data.size();
    }
     
    public void setSelectedItem(int position){
    	this.curPosition = position;
    }
    
    public int getSelectedItem(){
    	return this.curPosition;
    }
    
    public long getItemId(int position) {
        return position;
    }
 
    public View getView(int position, View convertView, ViewGroup parent) {
        View vi=convertView;
        if(vi == null)
        {
            LayoutInflater inflater = ((Activity)context).getLayoutInflater();
            vi = inflater.inflate(layoutResourceId, parent, false);
        }
        
        RPDataVO curItem = super.getItem(position);

        if(curItem != null){
            TextView rp_file_name = (TextView)vi.findViewById(R.id.rp_list_popup_file_name); // title
            TextView rp_file_order = (TextView)vi.findViewById(R.id.rp_list_popup_order); // title
            
            rp_file_name.setText(curItem.getTitle());
            
            
            if(curItem.isSelected){
            	if(curItem.getOrder() > 0){
            		rp_file_order.setText(curItem.getOrder()+"");
            		vi.setBackgroundResource(R.drawable.gradient_bg_hover);
            	}
    		}else{
    			vi.setBackgroundResource(R.drawable.gradient_bg);
            	rp_file_order.setText("");
    		}
            
            /*
            if(curItem.getOrder() > 0){
            	rp_file_order.setText(curItem.getOrder()+"");
            	vi.setBackgroundResource(R.drawable.gradient_bg_hover);
        		rp_file_name_checkbox.setChecked(true);
            }
            
            if(curPosition == position){
            	if(curItem.getOrder() > 0){
            		rp_file_order.setText(curItem.getOrder()+"");
            		vi.setBackgroundResource(R.drawable.gradient_bg_hover);
            		rp_file_name_checkbox.setChecked(true);
            	}
            	
            	//Toast.makeText(context, vi.getBackground() + "  --  " + context.getResources().getDrawable(R.drawable.setting_contact_gradient_bg_hover), Toast.LENGTH_SHORT).show();
            }
            if(curPosition == -9){
                vi.setBackgroundResource(R.drawable.gradient_bg);
            	rp_file_name_checkbox.setChecked(false);
            	rp_file_order.setText("");
            }
            
            if(curPosition == -6){
                vi.setBackgroundResource(R.drawable.gradient_bg);
            	rp_file_name_checkbox.setChecked(false);
            	rp_file_order.setText("");
            	
            	if(curItem.getOrder() > 0){
                	rp_file_order.setText(curItem.getOrder()+"");
                	vi.setBackgroundResource(R.drawable.gradient_bg_hover);
            		rp_file_name_checkbox.setChecked(true);
                }
            }
            */
            
        }
        
        return vi;
    }
}